<template>
	<view>
		<view class="u-page__item">
			<u-tabbar :value="tabIndex?tabIndex:0"  :fixed="true" :placeholder="false"
				activeColor="#1296db" :safeAreaInsetBottom="false">
				<u-tabbar-item :text="item.text" v-for="item,index in tabList" @click="changeTab(index)">
					
					<image class="u-page__item__slot-icon" slot="active-icon"
						:src="item.selectedIconPath"  v-if="tabIndex==index"></image>
						<image class="u-page__item__slot-icon" slot="inactive-icon"
							:src="item.iconPath"></image>
					
				</u-tabbar-item>
			</u-tabbar>
		</view>
	</view>
</template>

<script>
	export default {
		name:"tabbar",
		props:{
			tabIndex: Number,
			default:0
		},
		watch:{
			tabIndex(old,news){
				console.log('tabIndex',old,news,this.identity)
				this.changeTabList()
			}
		},
		data() {
			return {
				
				userTabList: [{
					"pagePath": "/src/pages/user_index/index",
					"iconPath": "/static/images/tabbar/merchant_n.png",
					"selectedIconPath": "/static/images/tabbar/merchant_y.png",
					"text": "名下商家"
				}, 
				
				{
					"pagePath": "/src/pages/user_league/index",
					"iconPath": "/static/images/tabbar/lianmeng_n.png",
					"selectedIconPath": "/static/images/tabbar/lianmeng_y.png",
					"text": "寻找联盟"
				}, 
				{
					"pagePath": "/src/pages/user_msg/index",
					"iconPath": "/static/images/tabbar/xiaoxi_n.png",
					"selectedIconPath": "/static/images/tabbar/xiaoxi_y.png",
					"text": "消息"
				}, 
				{
					"pagePath": "/src/pages/user_my/index",
					"iconPath": "/static/images/tabbar/my_n.png",
					"selectedIconPath": "/static/images/tabbar/my_y.png",
					"text": "我的"
				}, 
				
				],
				
				merchantTabList: [{
						"pagePath": "src/pages/merchant_merchants/index",
						"iconPath": "static/images/tabbar/merchant_y.png",
						"selectedIconPath": "static/images/tabbar/merchant_n.png",
						"text": "名下商家"
					},
					{
						"pagePath": "src/pages/merchant_index/index",
						"iconPath": "static/images/tabbar/home_n.png",
						"selectedIconPath": "static/images/tabbar/home_y.png",
						"text": "首页设置"
					},
					{
						"pagePath": "src/pages/merchant_person/index",
						"iconPath": "static/images/tabbar/person_n.png",
						"selectedIconPath": "static/images/tabbar/person_y.png",
						"text": "员工管理"
					}, {
						"pagePath": "src/pages/merchant_activity/index",
						"iconPath": "static/images/tabbar/activity_n.png",
						"selectedIconPath": "static/images/tabbar/activty_y.png",
						"text": "活动管理"
					}, {
						"pagePath": "src/pages/merchant_my/index",
						"iconPath": "static/images/tabbar/my_n.png",
						"selectedIconPath": "static/images/tabbar/my_y.png",
						"text": "个人中心"
					}
				],
				tabList:[],
				identity:'user'
			}
		},
		mounted() {
			console.log('mountedmounted')
			if(uni.getStorageSync('identity')=='merchant'){
				this.identity = 'merchant'
			}else{
					this.identity = 'user'
			}
			this.changeTabList()
		},
		methods: {
			changeTab(e){
				console.log('changeTab',e)
				this.tabIndex = e
				uni.switchTab({
					url:this.tabList[e].pagePath
				})
			},
			changeTabList() {
				if (this.identity == 'user') {
					this.tabList=this.userTabList
				}else if(this.identity == 'merchant') {
					this.tabList=this.merchantTabList
				this.$forceUpdate()
			}}
		}
	}
</script>

<style scoped lang="scss">
.u-page {
		padding: 0;

		&__item {

			&__title {
				color: $u-tips-color;
				background-color: $u-bg-color;
				padding: 15px;
				font-size: 15px;

				&__slot-title {
					color: $u-primary;
					font-size: 14px;
				}
			}

			&__slot-icon {
				width: 17px;
				height: 17px;
			}
		}
	}
</style>